# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/21 22:16
# @Author   : Robot-Zsj
"""
description:

i:
4
A,C,C,F
C,D,E,D
B,E,S,S
F,E,C,A
ACCESS

o:
0,0,0,1,0,2,1,2,2,2,2,3
"""
n = int(input())
matrix = [input().split(",") for _ in range(n)]
word = input()

used = [[False] * n for _ in range(n)]
path = []

offsets = ((0, 1), (1, 0), (0, -1), (-1, 0))


def dfs(i, j, k):
    if i < 0 or i >= n or j < 0 or j >= n or matrix[i][j] != word[k] or used[i][j]:
        return False
    path.append(f"{i},{j}")

    if len(path) == len(word):
        return True

    used[i][j] = True

    res = False
    for x, y in offsets:
        if dfs(i + x, j + y, k + 1):
            res = True
            break

    if not res:
        used[i][j] = False
        path.pop()

    return res


def getResult():
    for i in range(n):
        for j in range(n):
            if dfs(i, j, 0):
                return ",".join(path)
    return "N"


print(getResult())
